#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void merge (int* V1, int* V2, int* temp,int size1,int size2)
{
    int i=0, j=0, k=0;
    while (i < size1 && j < size2)
    {
        if (V1[i] < V2[j])
        {
            temp[k] = V1[i];
            i++;
            k++;

        }
        else if (V1[i] > V2[j])
        {
            temp[k] = V2[j];
            j++;
            k++;

        }
        else if (V1[i] == V2[j])
        {
            temp[k] = V1[i];
            i++;
            k++;

        }
    }
    if(i<size1)
        while (i<size1)
        {
            temp[k] = V1[i];
            i++;
            k++;
        }
    if(j<size2)
        while (j<size2)
        {
            temp[k] = V2[j];
            j++;
            k++;
        }
}

void bubble(int* V,int size)
{
    int i =-1,aux;
    while (i<size-1)
    {   i++;
        if (V[i]>V[i+1])
        {
            aux = V[i];
            V[i] = V[i+1];
            V[i+1] = aux;
            i=-1;
        }

    }


}

int main()
{
    int V1[50],V2[50],temp[100];
    srand(time(NULL));

    int i;
    for (i=0;i<50;i++)
    {
        V1[i] = rand()%500;
    }
    for (i=0;i<50;i++)
    {
        V2[i] = rand()%500;
    }
    bubble(V2,50);
    bubble(V1,50);
    merge(V1,V2,temp,50,50);
    for (i=0;i<50;i++)
        printf("%d ",V1[i]);

        printf("\n\n\n");
    for (i=0;i<50;i++)
        printf("%d ",V2[i]);

        printf("\n\n\n");
    for (i=0;i<100;i++)
        printf("%d ",temp[i]);

    return 0;
}
